describe("MoveFromListController for India", function() {
	var controller = null;
    var currentTransfer = null;
	
	beforeEach(function() {
        currentTransfer = App.BaseTransfer.create({
            fromAccount: null,
            currencyCode: null,
            toPayee: false,
            toAccount: App.BaseAccount.create({
                currencyCode: 'INR'
            }),
            payee: App.BaseAccount.create({
                accountCurrency: 'INR'
            })
        });
		var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        var t_moveHolderCtrl = App.MoveHolderController.create();
        App.MoveFromListController.reopen({
            init:function(){
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
                this.set('controllers.moveHolder', t_moveHolderCtrl);
            }
        });

        controller = App.MoveFromListController.create();
	});

    describe("setSourceAccount method test", function() {
        it("setSourceAccount - FromAccount is not cardAccount", function() {
            var account = App.HaveAccount.create({
                currencyCode: 'INR'
            });

            spyOn(App.getSession(), 'getCurrentTransfer').andReturn(currentTransfer);

            controller.setSourceAccount(account);

            expect(App.getSession().getCurrentTransfer).toHaveBeenCalled();
            expect(currentTransfer.get('fromAccount')).toEqual(account);
            expect(currentTransfer.get('currencyCode')).toEqual(account.currencyCode);
            expect(currentTransfer.get('isCashAdvance')).toBeFalsy();
        });
        it("setSourceAccount - FromAccount is cardAccount", function() {
            var account = App.CardAccount.create({
                currencyCode: 'INR'
            });

            spyOn(App.getSession(), 'getCurrentTransfer').andReturn(currentTransfer);

            controller.setSourceAccount(account);

            expect(App.getSession().getCurrentTransfer).toHaveBeenCalled();
            expect(currentTransfer.get('fromAccount')).toEqual(account);
            expect(currentTransfer.get('currencyCode')).toEqual(account.currencyCode);
            expect(currentTransfer.get('isCashAdvance')).toBeTruthy();
        });
    });

    it("selectListItem - if FromAccount is not cardAccount", function() {
        var account = jasmine.createSpy();
        spyOn(controller, 'setSourceAccount');
        spyOn(controller, 'transitionTo');

        controller.selectListItem(account);

        expect(controller.setSourceAccount).toHaveBeenCalledWith(account);
        expect(controller.transitionTo).toHaveBeenCalledWith('move.amount');
    });

    it("selectListItem - if FromAccount is cardAccount", function() {
        var account = App.CardAccount.create({
            currencyCode: 'INR'
        });

        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(currentTransfer);
        spyOn(controller, 'showLoading');
        spyOn(App.api_accountDetail, 'getAccountDetails').andCallFake(function(account,callback){
            callback(account);
        });
        spyOn(controller, 'setSourceAccount');
        spyOn(controller, 'transitionTo');

        controller.selectListItem(account);

        expect(App.getSession().getCurrentTransfer).toHaveBeenCalled();
        expect(controller.showLoading).toHaveBeenCalled();
        expect(App.api_accountDetail.getAccountDetails).toHaveBeenCalled();
        expect(controller.setSourceAccount).toHaveBeenCalledWith(account);
        expect(controller.transitionTo).toHaveBeenCalledWith('move.amount');
    });
});